/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Hogar;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class Fmicroondas extends Form implements CommandListener, ItemStateListener{
private ChoiceGroup potencia, tiempo;
private TextField txt;
private Ticker tick;
private Command atras, aceptar;
private boolean estado;
private int indicetxt, nivel, tiem;
private Hogar midlet;
public Fmicroondas(Hogar midlet){
super("Microondas");
this.midlet = midlet;
estado = false;
indicetxt = -1;
String potcad[] = {"Nivel1","Nivel2","Nivel3","Nivel4"};
String tiempocad[] = {"5 min","10 min","15 min","20 min","Seleccionar tiempo"};
potencia = new ChoiceGroup("Seleccione potencia",Choice.EXCLUSIVE,potcad,null);
tiempo = new ChoiceGroup("Seleccione tiempo",Choice.EXCLUSIVE,tiempocad,null);
txt = new TextField("Tiempo","",2,TextField.NUMERIC);
tick = new Ticker("Seleccione potencia y tiempo");
atras = new Command("Atras",Command.BACK,1);
aceptar = new Command("Aceptar",Command.OK,1);
this.append(potencia);
this.append(tiempo);
this.setTicker(tick);
this.addCommand(atras);
this.addCommand(aceptar);
this.setCommandListener(this);
this.setItemStateListener(this);
}
public void itemStateChanged(Item item){
if (item == potencia){
nivel = potencia.getSelectedIndex()+1;
}
else if (item == tiempo){
if (this.tiempo.getSelectedIndex() == 4){
indicetxt = this.append(txt);
nivel = 0;
}
else{
tiem = (tiempo.getSelectedIndex()+1)*5;
if (indicetxt != -1){
this.delete(indicetxt);
indicetxt = -1;
}
}
}
}
public void commandAction(Command c, Displayable d){
if (c == aceptar){
midlet.edificio.setMicroondas(true);
/*if (nivel != 0)
 * midlet.edificio.setNivelesMic(nivel, tiem);
 * else midlet.edificio.setNivelesMic(nivel, Integer.parseInt(txt.getString()));*/
 }
if (indicetxt != -1){
this.delete(indicetxt);
indicetxt = -1;
}
this.potencia.setSelectedIndex(0,true);
this.tiempo.setSelectedIndex(0,true);
this.txt.setString("");
midlet.verOpciones();
}
}